//
//  BindViewController.m
//  ZFPlatform
//
//  Created by magus on 11-6-3.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CardSettingViewController.h"
#import "CTextField.h"
#import "AccountSettingViewController.h"
#import "BindZaoShang1ViewController.h"
#import "BindPingAn1ViewController.h"


@implementation CardSettingViewController

@synthesize bindZaoShangButton;
@synthesize	bindPingAnButton;
@synthesize	bindJiaotongButton;
@synthesize	bindZhongGuoButton;


//通过xib资源初始化视图控制器
//
+ (CardSettingViewController*) InitFromXib
{
	self = [[CardSettingViewController alloc] 
			initWithNibName:@"CardSettingViewController" bundle:nil];
	return self;
}


//初始化界面
//
- (void) InitAllViews
{
	//设置导航栏标题
	[self setTitle:@"信用卡设置"];
	
	
	UIImage* bottonImg = [UIImage imageNamed:@"按钮（大）.png"];
	UIImage* bottonImg2 = [UIImage imageNamed:@"按钮（大）灰色.png"];
	
	//设置“招商”按钮图片
	[bindZaoShangButton setBackgroundImage:bottonImg2 forState:UIControlStateNormal];
	
	//设置“平安”按钮图片
	[bindPingAnButton setBackgroundImage:bottonImg2 forState:UIControlStateNormal];
	
	//设置“交通”按钮图片
	[bindJiaotongButton setBackgroundImage:bottonImg2 forState:UIControlStateNormal];
	
	//设置“中国”按钮图片
	[bindZhongGuoButton setBackgroundImage:bottonImg2 forState:UIControlStateNormal];
	
	[bottonImg release];
	[bottonImg2 release];
	
	
	//设置导航栏左按钮
	UIImage* leftImage = [UIImage imageNamed: @"导航栏按钮（返回）.png"];
	CGRect leftRect = CGRectMake(0, 0, leftImage.size.width, leftImage.size.height);
	UIButton* leftButton = [[UIButton alloc] initWithFrame:leftRect];
	[leftButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13.0]];
	[leftButton setTitle:@" 首页" forState:UIControlStateNormal];
	[leftButton setBackgroundImage:leftImage forState:UIControlStateNormal];
	[leftButton addTarget:self action:@selector(GoBackMain:) forControlEvents:UIControlEventTouchDown];
	UIBarButtonItem* leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
	self.navigationItem.leftBarButtonItem = leftItem;
	[leftItem release];
	[leftButton release];
	[leftImage release];
	
	//设置导航栏右按钮
	UIImage* rightImage = [UIImage imageNamed: @"导航栏按钮（设置）.png"];
	CGRect rightRect = CGRectMake(0, 0, rightImage.size.width, rightImage.size.height);
	UIButton* rightButton = [[UIButton alloc] initWithFrame:rightRect];
	[rightButton setBackgroundImage:rightImage forState:UIControlStateNormal];
	[rightButton addTarget:self action:@selector(AccountSetting:) forControlEvents:UIControlEventTouchDown];
	UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
	self.navigationItem.rightBarButtonItem = rightItem;
	[rightItem release];
	[rightButton release];
	[rightImage release];
}


//返回首页
//
- (void) GoBackMain: (id) sender
{
	//返回第一页
	NSArray *controllers = self.navigationController.viewControllers;
    UIViewController *ctrl = (UIViewController *)[controllers objectAtIndex:0];
    [self.navigationController popToViewController:ctrl animated:YES];
}


//进如账号设置
//
- (void) AccountSetting: (id) sender
{
	if(accountSettingViewController == nil)
		accountSettingViewController = [AccountSettingViewController InitFromXib];
	
	[self.navigationController pushViewController:accountSettingViewController animated:YES];
}


//响应“绑定招行卡”按钮
//
- (IBAction) OnClick_BindZaoShang: (id) sender
{
	if(bindZaoShang1ViewController == nil)
		bindZaoShang1ViewController = [BindZaoShang1ViewController InitFromXib];
	
	[self.navigationController pushViewController:bindZaoShang1ViewController animated:YES];
}


//响应“绑定平安卡”按钮
//
- (IBAction) OnClick_BindPingAn: (id) sender
{
	if(bindPingAn1ViewController == nil)
		bindPingAn1ViewController = [BindPingAn1ViewController InitFromXib];
	
	[self.navigationController pushViewController:bindPingAn1ViewController animated:YES];
}


//响应“绑定交通卡”按钮
//
- (IBAction) OnClick_BindJiaoTong: (id) sender
{
	NSLog(@"BindJiaoTong");
}


//响应“绑定中行卡”按钮
//
- (IBAction) OnClick_BindZhongGuo: (id) sender
{
	NSLog(@"BindZhongGu");
}


// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	[self InitAllViews];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc
{
	[bindPingAn1ViewController release];
	[bindZaoShang1ViewController release];
	[accountSettingViewController release];
	[bindZaoShangButton release];
	[bindPingAnButton release];
	[bindJiaotongButton release];
	[bindZhongGuoButton release];
	
    [super dealloc];
}


@end
